'use strict';

class Item {

  constructor(barcode, name, unit, price = 0.00) {
    this.barcode = barcode;
    this.name = name;
    this.unit = unit;
    this.price = price;
  }

  static all() {
    return [
      new Item('ITEM000000', '可口可乐', '瓶', 3.00),
      new Item('ITEM000001', '雪碧', '瓶', 3.00),
      new Item('ITEM000002', '苹果', '斤', 5.50),
      new Item('ITEM000003', '荔枝', '斤', 15.00),
      new Item('ITEM000004', '电池', '个', 2.00),
      new Item('ITEM000005', '方便面', '袋', 4.50)
    ];
  }
}

class itemContainer{

  constructor(){
    this.itemsInfo = {};
  }
  
  itemInfoPush(itemObj){
    var obj = {};
    obj.name = itemObj.name;
    obj.unit = itemObj.unit;
    obj.price = itemObj.price;
    obj.promotion = 0;
    this.itemsInfo[itemObj.barcode] = obj;
  }
}

class itemBuyContainer{

  constructor(){
    this.buyList = [];
    this.paySum = 0;
    this.saveMoney = 0;
  }
  
  buyListPush(itemInfo,buyNum){
    for (var i = 0; i < this.buyList.length; i++){
      if(this.buyList[i].name == itemInfo.name){
        break;
      }
    }
    if(i == this.buyList.length){
      itemInfo.buyNum = buyNum;
      itemInfo.pay = 0;
      this.buyList.push(itemInfo);
    }else{
      this.buyList[i].buyNum += buyNum;
    }
  }
}
